<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="avicit.platform6.commons.utils.ViewUtil"%>
<%@ page import="avicit.platform6.commons.utils.ComUtil"%>
<%@ taglib prefix="sec" uri="/WEB-INF/tags/shiro.tld" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page import="avicit.platform6.core.locale.PlatformLocalesJSTL"%>
<%@page import="java.util.Locale"%>
<%@page import="avicit.platform6.api.session.SessionHelper"%>
<%@page import="avicit.platform6.api.sysshirolog.impl.AfterLoginSessionProcess"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<base href="<%=ViewUtil.getRequestPath(request)%>">
<% 
Object lang=session.getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
String languageCode="zh_CN";
if(lang!=null){
	languageCode=lang.toString();
}
	Locale locale =SessionHelper.getLocaleByUser(request);
%>
<jsp:include page="/avicit/platform6/component/common/EasyUIJsInclude.jsp"></jsp:include>
<jsp:include page="/avicit/im/common/ImUIJSCSSInclude.jsp"></jsp:include>
<script src="static/js/platform/component/common/exportData.js" type="text/javascript"></script>
<script type="text/javascript"
	src="avicit/im/lantop/basic/reportmanager/locale/language_<%=languageCode%>.js"></script>
<script type="text/javascript"
	src="avicit/im/lantop/basic/reportmanager/js/LantopFineReport.js"></script>
<link href="static/css/custom/lantop/css/custom.css" type="text/css"  rel="stylesheet">
<title>报表管理</title>
<script type="text/javascript">
	var baseHref = '<%=ViewUtil.getRequestPath(request)%>';
</script>




<script type="text/javascript">
	//  接收后台传递的参数
	var sysId = '${sysId}';
	var orgId = '${orgId}';
	var dialogId = '${dialogId}';
	var tableNameIds = '${tableNameIds}';
	var templateId = '${templateId}';
	var lantopFineReport;
	var type = "root";
	$(function(){
		lantopFineReport = new LantopFineReport("<%=ViewUtil.getRequestPath(request)%>", {
			op : "write",
			__showtoolbar__ : "false"
		}, "reportView", false);
		$("#reportTree").tree({
			checkbox : false, 			// 是否带复选框
			lines : true, 				// 线条 
			method : 'post',
			url : "platform/im/lantop/basic/ReportManagerController/gettree/-1/null?sysId="+sysId, 
			dataType : "json", /* 数据格式 */
			formatter:function(node){
				if(node._parentId=="-1"){
					//_self._rootId=node.id;
				}
				if(node.attributes && node.attributes.s){
					return '<a style="color:#fff;font-weight:normal;background:#3399ff;padding:0 4px;">' + node.text + '</a>';
				}else{
					return node.text;
				}
			},
			
			loadFilter : function(data) {
				// 过滤后台返回的数据，处理不同JSON结构
				if (data.data) {
					return data.data;
				} else {
					return data;
				}
			},
			
			onClick : function(node) {
				$("#reportTree").tree('select', node.target);
				// 模板， 加载其所对应的模板
				if (node.attributes.reportType == '1') {
					lantopFineReport.submit({
						SQL : "SELECT ' ' FROM DUAL",
						reportlet : node.attributes.cptFileName
					});
				}
				type = "nRoot";
			},
			formatter : function(node) {
				return '<span title="' + node.text + '">' + node.text + '</span>';
			}
		});
		
		
		//根组织树初始化
		$("#reportTreeRoot").tree({
			checkbox : false, 			// 是否带复选框
			lines : true, 				// 线条 
			method : 'post',
			url : "platform/im/lantop/basic/ReportManagerController/gettree/-1/root?sysId="+sysId, 
			dataType : "json", /* 数据格式 */
			formatter:function(node){
				if(node._parentId=="-1"){
					//_self._rootId=node.id;
				}
				if(node.attributes && node.attributes.s){
					return '<a style="color:#fff;font-weight:normal;background:#3399ff;padding:0 4px;">' + node.text + '</a>';
				}else{
					return node.text;
				}
			},
			
			loadFilter : function(data) {
				// 过滤后台返回的数据，处理不同JSON结构
				if (data.data) {
					return data.data;
				} else {
					return data;
				}
			},
			
			onClick : function(node) {
				$("#reportTreeRoot").tree('select', node.target);
				// 模板， 加载其所对应的模板
				if (node.attributes.reportType == '1') {
					lantopFineReport.submit({
						SQL : "SELECT ' ' FROM DUAL",
						reportlet : node.attributes.cptFileName
					});
				}
				type = "root";
			},
			formatter : function(node) {
				return '<span title="' + node.text + '">' + node.text + '</span>';
			}
		
		});
		
	});
	
	// 确定按钮
	function save(){
		// 需要判断是否是已经配置过的，如果是则直接打印, 否则则需要弹出配置窗口
		var node;
		if(type == "root"){
			node = $("#reportTreeRoot").tree('getSelected');
		}else{
			node = $("#reportTree").tree('getSelected');
		}
		var templateId = node.id;
		if(node == null || node.length == 0 || node.attributes.reportType == '0'){
			//'提示', "请选择一个模板！"
			$.messager.alert("<%=PlatformLocalesJSTL.getBundleValue("lantop.remind","i18n.lantop",locale)%>"," <%=PlatformLocalesJSTL.getBundleValue("lantop.basicdatamanager.reportmanager.printselectreport.choosetemplate","i18n.lantop",locale)%>", 'warning');
			return ;
		}
		var outPutFields;
		if(node.attributes.hasField){
			outPutFields = node.attributes.fields;  // 取出应输出字段
		} else {
			outPutFields = $(
					$(window.frames["reportView"].document).find("#r-0-0").find(
							"td")[0]).text();
			if ("" == outPutFields) {//无输出字段
				$.messager.alert(commonLang.tip.alert, commonLang.tip.templateNoFiled, 'warning');
				return;
			}
		}
		
		//var resultDataSource = node.attributes.resultDataSource;
		
		
		outPutFields = encodeURI(encodeURI(outPutFields));
		

		// 总是打开数据源配置界面, 
		//if(undefined != resultDataSource ){
			// 未配置过数据源, 打开配置界面
		var dialogId = "printfSelectConfigDialog";
		//'报表配置'
		var config = new CommonDialog(dialogId, "900", "450",
					'platform/im/lantop/basic/ReportManagerController/printfreportconfig?dialogId=' + dialogId + "&outPutFields=" + outPutFields + "&templateId=" +templateId + "&tableNameIds=" + tableNameIds +"&sysId=" + sysId, commonLang.tip.templateConfig, false, true, false,false,true);
		config.show();
			//parent.$(".panel-tool-max panel-tool-restore").css({display : 'none'});
							
			
		//}
		
	}
	
	// 取消按钮
	function cancel(){
		// 需要刷新父页面
		parent.reLoadTree();
		parent.reLoadTreeRoot();
		parent.$("#" + dialogId).dialog('close');
		
	}


</script>
<style>
	 .tree-file{
	    margin-top:5px !important; 
	 }
	</style>
<body class="easyui-layout" data-options="fit:true">
	
     <div data-options="region:'center',title:'center title',split:false, noheader:true" style="overflow:hidden;">
     		<div id="cc" class="easyui-layout" fit="true" style="width:100%;height:100%;padding-left : 20px;">
				<c:if test="${orgId != 'ORG_ROOT'}">
				    <div data-options="region:'south'" id="remove_scroll_bars" style="height:280px;border-top:1px solid #dedede;">
				    	<ul id="reportTree"></ul>
				    </div>   
				</c:if> 
			    <div data-options="region:'center'">
			     	<ul id="reportTreeRoot"></ul>
			    </div>   
			</div>  
     </div>   
	<div style="display: none;">
		<iframe id="reportView" name = "reportView" width="100%" height="100%"  frameborder="0"></iframe>
	</div>	
	<div data-options="region:'south',title:'South Title',split:false, noheader:true" style="height: 60px; overflow: hidden;" class="datagrid-toolbar">
	 
	 	<table align="center"  style="margin-top:18px;">
    			<tr>
    				<td>
    					<sec:accesscontrollist  hasPermission="3" domainObject="excel_export_button_exportData" >
	 	<%--确定 --%>
		            <a class="easyui-linkbutton selbtnc"  iconCls="icon-im-save"
				  	onclick="save();" href="javascript:void(0);"><%=PlatformLocalesJSTL.getBundleValue("lantop.basicdatamanager.reportmanager.printselectreport.confirm","i18n.lantop",locale)%></a>	
															<%--取消 --%>
					</sec:accesscontrollist>
    				
    					<sec:accesscontrollist  hasPermission="3" domainObject="excel_export_button_cancle" >
							<%--关闭--%>
	             	<a class="easyui-linkbutton selbtnc"  iconCls="icon-im-back"  style="margin-left: 20px;"
					onclick="cancel();" href="javascript:void(0);"><%=PlatformLocalesJSTL.getBundleValue("lantop.basicdatamanager.reportmanager.printselectreport.cancle","i18n.lantop",locale)%></a> 
	                </sec:accesscontrollist>
    				</td>
    			</tr>
    		</table>
		
	 </div>  
</body>
<!-- 滚动条样式设置  yangzengzhi 2019-06-25-->
<script type="text/javascript" src="static/js/platform/index/js/divscroll.js" ></script>
<script>
 $(function(){
  $("#remove_scroll_bars").perfectScrollbar();
 });
 window.onresize = function(){
	    setTimeout(function(){
	        $("#printfSelectConfigDialog").dialog('resize',{
	            width: $(window).width(),
	            height: $(window).height()
	        });
	    },300);
	};
</script>
<!-- end-->
</html>